/****************************************************
	文件：CommandMemento.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/5/31 17:57:23
	功能：命令备忘录
*****************************************************/

using System.Collections;
using System.Collections.Generic;
using HTUtility;
using UnityEngine;

namespace AIModule.Utility.Example
{
    public class CommandMemento : HTSingleton<CommandMemento>
    {
        private List<CommandBase> mCommandList = new List<CommandBase>();
        private List<BlackboardItem> mBlackboardItemList = new List<BlackboardItem>();

        /// <summary>
        /// 重置
        /// </summary>
        public void Reset()
        {
            mCommandList.Clear();
            mBlackboardItemList.Clear();
        }
        /// <summary>
        /// 重播
        /// </summary>
        public IEnumerator Replay(float waitTime)
        {
            if (mCommandList.Count != mBlackboardItemList.Count)
            {
                Debug.LogError("CommandMemento Replay Error !");
            }
            GameRoot.Instance.DoBeforeReplay();
            WaitForSeconds wait = new WaitForSeconds(waitTime);
            Debug.LogWarning("//--------------------开始重播--------------------//");
            for (int i = 0; i < mCommandList.Count; i++)
            {
                if (i % 2 == 0)
                {
                    Debug.LogWarningFormat("//------------------第 {0} 回合------------------//", i / 2 + 1);
                }
                mCommandList[i].Execute(mBlackboardItemList[i]);
                if (i % 2 == 1)
                {
                    GameRoot.Instance.LogCurrentState();
                    yield return wait;
                }
            }
            Debug.LogWarning("//--------------------重播结束--------------------//");
        }
        public void AddCommand(CommandBase command, BlackboardItem bb)
        {
            mCommandList.Add(command);
            mBlackboardItemList.Add(bb);
        }
        public void RemoveCommand(CommandBase command, BlackboardItem bb)
        {
            mCommandList.Remove(command);
            mBlackboardItemList.Remove(bb);
        }
    }
}